﻿using DotNet.Auth.Service;
using DotNet.Web.Areas.AuthWeb.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;

namespace DotNet.Web.Areas.Mobile.Controllers
{
    public class M_ModifyUserPasswordController : AuthController
    {
        // GET: Mobile/M_ModifyUserPassword
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult ModifyUserPassword(string currentPwd, string newPwd)
        {
            var userService = AuthService.User;
            if (!userService.ValidUserPassword(CurrentUserId, currentPwd))
            {
                return Json(false, "当前密码输入不正确,请重新输入");
            }
            if (!userService.formatPassword(newPwd))
            {
                return Json(false, "当前密码输入格式不正确,请重新输入,输入格式：长度在8~18之间，由数字和英文字母混合而成");
            }
            var result = userService.UpdatePassword(new[] { CurrentUserId }, newPwd);
            return Json(result);
            //bool bol = MD5(newPwd);
            //if (bol == false)
            //{
            //    return Json(false, "当前密码输入格式不正确,请重新输入,输入格式：长度在8~18之间，由数字和英文字母混合而成");
            //}
        }
        //密码(长度在8~18之间，由数字和26个英文字母混合而成)
        //private bool MD5(string pwd)
        //{
        //    string reg = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,18}$";
        //    return Regex.IsMatch(pwd, reg);
        //}
    }
}